﻿using System;
using System.Collections.Generic;
using System.Text;

using Galaxy.ModuleInterface;
using Galaxy.ModuleInterface.Messages;
using System.IO;

namespace Galaxy.TestModule
{
    public class CTextWriterModule : CGalaxyModule, IGalaxyModule
    {
        private string f_Text;
        private TextWriter f_TextWriter;


        public CTextWriterModule(TextWriter Writer, string Text)
            : base("Принтер")
        {
            f_Text = Text;
            f_TextWriter = Writer;
        }

        public CTextWriterModule(string Name, TextWriter Writer, string Text)
            : base(Name)
        {
            f_Text = Text;
            f_TextWriter = Writer;
        }

        public override void Start()
        {
#if DEBUG
            Console.WriteLine("Принтер запущен");
#endif
        }

        public override void Stop()
        {
#if DEBUG
            Console.WriteLine("Принтер остановлен");
#endif
        }

        public override void Initialize()
        {
#if DEBUG
            Console.WriteLine("Принтер проинициализирован");
#endif
        }

        public override void ProcessMessage(IGalaxyModuleMessage Message)
        {
            base.ProcessMessage(Message);
            ProcessMessage(Message as CTextMessage);
            ProcessMessage(Message as CInvokeMessage);
        }

        protected virtual void ProcessMessage(CInvokeMessage Message)
        {
            if(Message == null) 
                return;
            f_TextWriter.WriteLine(f_Text);
            System.Windows.Forms.MessageBox.Show(f_Text);
        }

        protected virtual void ProcessMessage(CTextMessage Message)
        {
            if(Message == null)
                return;
            f_Text = Message.Data;
        }
    }
}
